//备注：拷贝代码请加上作者信息
//作者：王海涛
//邮箱：1126471088@qq.com
//版本：V1.0.0
/*
    这个是一个简单的非RTOS的时间片任务调度器示例。
*/
#include "time_slice_task_os.h"
#include "stdio.h"

#include "../../User/BSP/Timer_BSP/timer_bsp.h"

static void Task_1(void)
{
    printf("Task_1 Run\r\n");
}

static void Task_2(void)
{
    printf("Task_2 Run\r\n");
}

static void Task_3(void)
{
    printf("Task_3 Run\r\n");
}

void WHT_Idle_Task(void)        //空闲任务
{
    static uint32_t abc;
    if (abc++ >= 200000)
    {
        abc = 0;
        printf("Idle\r\n");
    }
}


static void Time_IT_Callback(void)
{
    WHT_SysTick_ms++;
}




void WHT_Test_main(void)
{
    WHT_Timer_Basic_Config_t Basic_config = 
    {
        .PreemptionPriority = 15,
        .SubPriority =0,
        .Interrupt_Callback = Time_IT_Callback,
    };

    WHT_Timer_Config_t timer_config =
    {
        .Name = Timer1,
        .Cycle_ns = 1000000,
        .Mode = Timer_Basic,
        .Config_Count = 1,
        .Config = (void*)&Basic_config,
    };



    WHT_Time_Slice_Task_OS.install(Task_1);    
    WHT_Time_Slice_Task_OS.install(Task_2);
    WHT_Time_Slice_Task_OS.install(Task_3);
    
    WHT_Time_Slice_Task_OS.set_cycle(Task_1, 500);
    WHT_Time_Slice_Task_OS.set_cycle(Task_2, 1000);
    WHT_Time_Slice_Task_OS.set_cycle(Task_3, 2000);
    
    WHT_Time_Slice_Task_OS.start(Task_1);
    WHT_Time_Slice_Task_OS.start(Task_2);
    WHT_Time_Slice_Task_OS.start(Task_3);
    
    WHT_Timer_BSP.WHT_Config(&timer_config);
    WHT_Timer_BSP.WHT_Start(&timer_config);

    
    while(1)
    {
        WHT_Time_Slice_Task_OS.loop();
    }
}
